package com.edu.kindergarten.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.edu.kindergarten.entity.SimpleAdapterItem;

public class SimpleGridAdapter extends BaseAdapter {

	private static final String TAG = "SimpleGridAdapter";

	private Context context;
	private int layoutId;
	private List<SimpleAdapterItem> listData;
	private int to[];
	
	public SimpleGridAdapter(Context context, int layoutId,
			List<SimpleAdapterItem> listData, int to[]) {
		this.context = context;
		this.layoutId = layoutId;
		this.listData = listData;
		this.to = to;
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return listData.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return listData.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder holder;

		if (convertView == null) {
			LayoutInflater layoutInflator = LayoutInflater.from(context);
			convertView = layoutInflator.inflate(layoutId,parent,false);
			holder = new ViewHolder();
			holder.imageView = (ImageView) convertView.findViewById(to[0]);
			holder.textView = (TextView) convertView.findViewById(to[1]);
			convertView.setTag(holder);
		}else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		holder.imageView.setImageResource(listData.get(position).image);
		holder.textView.setText(listData.get(position).txt);
		//ImageLoader.getInstance().displayImage("drawable://" + listData[position], holder.imageView);

		return convertView;
	}

	static class ViewHolder {
		ImageView imageView;
		TextView textView;
	}

}
